package cn.com.code.hwjs;

import java.util.Scanner;

/**
 * HJ67 24点游戏算法
 * https://www.nowcoder.com/practice/fbc417f314f745b1978fc751a54ac8cb?tpId=37&tqId=21290&rp=1&ru=/exam/oj&qru=/exam/oj&sourceUrl=%2Fexam%2Foj%3Fdifficulty%3D3%26page%3D1%26pageSize%3D50%26search%3D%26tab%3D%25E5%2590%258D%25E4%25BC%2581%25E7%25AC%2594%25E8%25AF%2595%25E7%259C%259F%25E9%25A2%2598%26topicId%3D37&difficulty=3&judgeStatus=undefined&tags=&title=
 *
 * @author zhengpei
 * @date 2022/5/14
 */
public class Hwjs67 {

  public static boolean[] visited = new boolean[4];
  public static int[] nums = new int[4];
  public static boolean flag = false;

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    while (sc.hasNext()) {
      for (int i = 0; i < 4; i++) {
        nums[i] = sc.nextInt();
      }
      dfs(0, 0);
      System.out.println(flag);
    }
  }

  private static void dfs(int start, double sum) {
    // 地柜终止条件
    if (start == 4) {
      if (sum == 24) {
        flag = true;
      }
    } else {
      start++;
      for (int i = 0; i < 4; i++) {
        // 标记这个值有没有访问过
        if (!visited[i]) {
          visited[i] = true;
          dfs(start, sum + nums[i]);
          dfs(start, sum - nums[i]);
          dfs(start, sum * nums[i]);
          dfs(start, sum / nums[i]);
          visited[i] = false;
        }
      }
    }
  }

}
